package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetGainModeMapper;
import com.lhys.pojo.AssetGainMode;
import com.lhys.service.AssetGainModeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 取得方式 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Service
public class AssetGainModeServiceImpl implements AssetGainModeService {
    @Autowired
    private AssetGainModeMapper gainModeMapper;

    @Override
    @Transactional
    public Boolean saveAssetGainMode(AssetGainMode assetGainMode) {
        try {
            if (assetGainMode.getId() == null) {
                if (assetGainMode.getCreateTime() == null) {
                    assetGainMode.setCreateTime(new Date());
                }
                return gainModeMapper.addAssetGainMode(assetGainMode) > 0;
            }
            return gainModeMapper.updateAssetGainMode(assetGainMode) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetGainModeById(Integer id) {
        return gainModeMapper.delAssetGainMode(id) > 0;
    }

    @Override
    public AssetGainMode getAssetGainModeById(Integer id) {
        return gainModeMapper.getAssetGainModeById(id);
    }

    @Override
    public PageInfo<AssetGainMode> getAssetGainModeList(AssetGainMode assetGainMode, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetGainMode> list = gainModeMapper.getAssetGainModeByCodeAndTitleOrRemarkList(assetGainMode);
        PageInfo<AssetGainMode> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
